##############################
#   敌人函数   
#   by Jerry Yang      
#   UUZ0226            
#############################
import random
import time
import math
import hero_function as hf

def EnemySpecies():
    species = ['鼠','牛','虎','兔','龙','蛇','马','羊','猴','鸡','狗','猪','猫']
    species += ['狐','狼','虫','史莱姆','怪','妖','精','鬼','魂','象','神','仙']
    name = random.choice(species)
    return name

def EnemyName():
    head = random.randint(0xb0, 0xf7)
    body = random.randint(0xa1, 0xfe)
    val = f'{head:x} {body:x}'
    str = bytes.fromhex(val).decode('gb2312')
    return str

def EnemyInf(inf,enemy_inf):
    AdventuresLevel = inf['Level']
    EnemysLevel = random.randrange(1,AdventuresLevel+1)
    EnemysLevel = 1
    EnemyName = enemy_inf['EnemyName']
    enemy_inf['EnemyLevel'] = EnemysLevel
    enemy_inf['EnemyHP'] = EnemysLevel*100
    enemy_inf['EnemyAttack'] = random.randrange(1,100)*EnemysLevel
    time.sleep(1)
    return enemy_inf

def show_enemy(ai_settings,screen,enemy_inf):
    N = enemy_inf['EnemyName']
    A = enemy_inf['EnemyAttack']
    H = enemy_inf['EnemyHP']
    Lv = enemy_inf['EnemyLevel']
    text = ['名字：' + N ,
            '攻击：'+ str(A),
            'HP：'+ str(H),
            '等级：'+ str(Lv),
            ]
    for  i in range(0, len(text)):
        if i == 2:
            ai_settings.text_color = (255, 0, 0)
        else:
            ai_settings.text_color = (30,30,30)
        m = hf.show_in_right(ai_settings, screen,text,i)

#以下是需要改的部分
def EnemyHurt(inf,enemy_inf,Attack,EnemyAlive):
    blood_minute = math.ceil(Attack)
    EnemyHP = enemy_inf['EnemyHP']
    if blood_minute >= 0:
        print('Enemy get '+str(blood_minute)+' hurt!')
    elif blood_minute < 0:
        blood_minute = 0
        print('Enemy get '+str(blood_minute)+' hurt!')
    EnemyHP -= blood_minute
    time.sleep(1)   
    if EnemyHP <= 0:
        print('Victory!')
        inf = Character.get_exp(inf,enemy_inf['EnemyLevel'])
        time.sleep(1)
        EnemyAlive = False
    elif EnemyHP > 0:
        enemy_inf['EnemyHP'] = EnemyHP
    return(inf,enemy_inf,EnemyAlive)